




/*
'===============================================================================
'  TuanHuy.BL.GalleryCategoryManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using TuanHuy.BLL;
using TuanHuy.DAL;
using TuanHuy.DAL.EntityClasses;
using TuanHuy.DAL.FactoryClasses;
using TuanHuy.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace TuanHuy.BLL
{
	public class GalleryCategoryManagerBase : ManagerBase
	{
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		
		public GalleryCategoryManagerBase()
		{
			// Nothing for now.
		}
		
		/*public override string TableName()
        {
            return "GalleryCategory";
        }*/
		
		public GalleryCategoryEntity Insert(GalleryCategoryEntity _GalleryCategoryEntity)
		{
			return Insert(_GalleryCategoryEntity, "");
		}
		
		public GalleryCategoryEntity Insert(GalleryCategoryEntity _GalleryCategoryEntity, string controlId)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(_GalleryCategoryEntity, true);
				GalleryCategoryFields field = new GalleryCategoryFields();
                //LogEntity(_GalleryCategoryEntity, field, AcInsert, controlId);
			}
			return _GalleryCategoryEntity;
		}

		
		public GalleryCategoryEntity Insert(int CatogeryId, string CatogeryName)
		{
			GalleryCategoryEntity _GalleryCategoryEntity = new GalleryCategoryEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_GalleryCategoryEntity.CatogeryId = CatogeryId;
				_GalleryCategoryEntity.CatogeryName = CatogeryName;
				GalleryCategoryFields field = new GalleryCategoryFields();
                //LogEntity(_GalleryCategoryEntity, field, AcInsert);
				adapter.SaveEntity(_GalleryCategoryEntity, true);
			}
			return _GalleryCategoryEntity;
		}

		/*public GalleryCategoryEntity Insert(string CatogeryName)
		{
			GalleryCategoryEntity _GalleryCategoryEntity = new GalleryCategoryEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_GalleryCategoryEntity.CatogeryName = CatogeryName;
				adapter.SaveEntity(_GalleryCategoryEntity, true);
				GalleryCategoryFields field = new GalleryCategoryFields();
                //LogEntity(_GalleryCategoryEntity, field, AcInsert);
			}
			return _GalleryCategoryEntity;
		}*/
		
		public bool Update(GalleryCategoryEntity _GalleryCategoryEntity)
        {
            return Update(_GalleryCategoryEntity, "");
        }

		public bool Update(GalleryCategoryEntity _GalleryCategoryEntity, string controlId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(GalleryCategoryFields.CatogeryId == _GalleryCategoryEntity.CatogeryId);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_GalleryCategoryEntity, filter);
				toReturn = true;
				
				GalleryCategoryFields field = new GalleryCategoryFields();
                //LogEntity(_GalleryCategoryEntity, field, AcUpdate, controlId);
			}
			return toReturn;
		}
		
		public bool Update(GalleryCategoryEntity _GalleryCategoryEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_GalleryCategoryEntity, filter);
				toReturn = true;
				
				GalleryCategoryFields field = new GalleryCategoryFields();
                //LogEntity(_GalleryCategoryEntity, field, AcUpdate);
			}
			return toReturn;
		}

		public bool Update(int CatogeryId, string CatogeryName)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				GalleryCategoryEntity _GalleryCategoryEntity = new GalleryCategoryEntity(CatogeryId);
				if (adapter.FetchEntity(_GalleryCategoryEntity))
				{
				
					_GalleryCategoryEntity.CatogeryName = CatogeryName;
					adapter.SaveEntity(_GalleryCategoryEntity, true);
					toReturn = true;
					
					GalleryCategoryFields field = new GalleryCategoryFields();
					//LogEntity(_GalleryCategoryEntity, field, AcUpdate);
				}
			}
			return toReturn;
		}

		public bool Delete(int CatogeryId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				GalleryCategoryEntity _GalleryCategoryEntity = new GalleryCategoryEntity(CatogeryId);
				if (adapter.FetchEntity(_GalleryCategoryEntity))
				{
					adapter.DeleteEntity(_GalleryCategoryEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("GalleryCategoryEntity", null);
			}
		}
		
		
		public int DeleteByCatogeryId(int CatogeryId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleryCategoryFields.CatogeryId == CatogeryId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("GalleryCategoryEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByCatogeryName(string CatogeryName)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleryCategoryFields.CatogeryName == CatogeryName);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("GalleryCategoryEntity", filter);
			}
			return toReturn;
		}
		

		
		public GalleryCategoryEntity SelectOne(int CatogeryId)
		{
			GalleryCategoryEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				GalleryCategoryEntity _GalleryCategoryEntity = new GalleryCategoryEntity(CatogeryId);
				if (adapter.FetchEntity(_GalleryCategoryEntity))
				{
					toReturn = _GalleryCategoryEntity;
				}
			}
			return toReturn;
		}

		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GalleryCategoryCollection = new EntityCollection(new GalleryCategoryEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GalleryCategoryCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection<GalleryCategoryEntity>
		public EntityCollection<GalleryCategoryEntity> SelectAllLST()
		{
			EntityCollection<GalleryCategoryEntity> _GalleryCategoryCollection = new EntityCollection<GalleryCategoryEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleryCategoryCollection, null, 0, null);
			}
			return _GalleryCategoryCollection;
		}
		
		// Return EntityCollection<GalleryCategoryEntity>
		public EntityCollection<GalleryCategoryEntity> SelectAllLST_Paged(int PageNumber, int PageSize)
		{
			EntityCollection<GalleryCategoryEntity> _GalleryCategoryCollection = new EntityCollection<GalleryCategoryEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleryCategoryCollection, null, 0, null, null, PageNumber, PageSize);
			}
			return _GalleryCategoryCollection;
		}


		
		// Return EntityCollection<GalleryCategoryEntity>
		public EntityCollection<GalleryCategoryEntity> SelectByCatogeryIdLST(int CatogeryId)
		{
			EntityCollection<GalleryCategoryEntity> _GalleryCategoryCollection = new EntityCollection<GalleryCategoryEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleryCategoryFields.CatogeryId == CatogeryId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleryCategoryCollection, filter, 0, null);
			}
			return _GalleryCategoryCollection;
		}
		
		// Return EntityCollection<GalleryCategoryEntity>
		public EntityCollection<GalleryCategoryEntity> SelectByCatogeryIdLST_Paged(int CatogeryId, int PageNumber, int PageSize)
		{
			EntityCollection<GalleryCategoryEntity> _GalleryCategoryCollection = new EntityCollection<GalleryCategoryEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleryCategoryFields.CatogeryId == CatogeryId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleryCategoryCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _GalleryCategoryCollection;
		}
		
		// Return DataTable
		public DataTable SelectByCatogeryIdRDT(int CatogeryId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GalleryCategoryCollection = new EntityCollection(new GalleryCategoryEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleryCategoryFields.CatogeryId == CatogeryId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GalleryCategoryCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByCatogeryIdRDT_Paged(int CatogeryId, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GalleryCategoryCollection = new EntityCollection(new GalleryCategoryEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleryCategoryFields.CatogeryId == CatogeryId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GalleryCategoryCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		// Return EntityCollection<GalleryCategoryEntity>
		public EntityCollection<GalleryCategoryEntity> SelectByCatogeryNameLST(string CatogeryName)
		{
			EntityCollection<GalleryCategoryEntity> _GalleryCategoryCollection = new EntityCollection<GalleryCategoryEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleryCategoryFields.CatogeryName == CatogeryName);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleryCategoryCollection, filter, 0, null);
			}
			return _GalleryCategoryCollection;
		}
		
		// Return EntityCollection<GalleryCategoryEntity>
		public EntityCollection<GalleryCategoryEntity> SelectByCatogeryNameLST_Paged(string CatogeryName, int PageNumber, int PageSize)
		{
			EntityCollection<GalleryCategoryEntity> _GalleryCategoryCollection = new EntityCollection<GalleryCategoryEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleryCategoryFields.CatogeryName == CatogeryName);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_GalleryCategoryCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _GalleryCategoryCollection;
		}
		
		// Return DataTable
		public DataTable SelectByCatogeryNameRDT(string CatogeryName)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GalleryCategoryCollection = new EntityCollection(new GalleryCategoryEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleryCategoryFields.CatogeryName == CatogeryName);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GalleryCategoryCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByCatogeryNameRDT_Paged(string CatogeryName, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _GalleryCategoryCollection = new EntityCollection(new GalleryCategoryEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(GalleryCategoryFields.CatogeryName == CatogeryName);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_GalleryCategoryCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}


		
		

	}
}
